<?php
declare(strict_types=1);
namespace App\Api;

use App\ApiController;

use Field\SysMenuConst;
use Field\SysRoleAuthConst;
use Field\SysRoleConst;

// hook api_menu_use.php

/**
 * @title   配置下发
 * @auth    true
 * @login   true
 * @rank    3
 */
class Conf extends ApiController
{
    // hook api_menu_start.php

    /**
     * @title  获取用户菜单
     * @rank    99
     */
    public function action_Menu(): void
    {
        $menu = $this->SysMenu->CacheMenu();
        if (!empty($this->token->RoleID) && $this->token->RoleID != 1) {
            $role = $this->SysRole->read_by_index($this->token->RoleID);
            empty($role->Status) and $this->response('0401', [], '权限组已禁用');
            $role = $this->SysRoleAuth->select([SysRoleAuthConst::RoleID => $this->token->RoleID]);
            $nodes = $role ? arrlist_values($role, SysRoleAuthConst::Node) : [];
            foreach ($menu as $k => $v) {
                $v[SysMenuConst::Node] = str_replace('/', '_', $v[SysMenuConst::Node]);
                if ( $v[SysMenuConst::Method]) {
                    $v[SysMenuConst::Node] .= '_' . $v[SysMenuConst::Method];
                }
                if (!xn_in_array($v[SysMenuConst::Node], $nodes)) {
                    unset($menu[$k]);
                }
            }
        }
        $menus = [];

        foreach ($menu as $v) {
            if($v[SysMenuConst::Node]=="zxadmin"){
                continue;
            }
            if($v[SysMenuConst::ParentNode]=="zxadmin"){
                $v[SysMenuConst::ParentNode]="";
            }
            $m = [
                'path' => '/' . $v[SysMenuConst::Node],
                'parentPath' => '/' . $v[SysMenuConst::ParentNode],
                'name' => $v[SysMenuConst::Node],
                'rank' => $v[SysMenuConst::Rank],
                'component' => $v[SysMenuConst::Component] ?: 'vlist/index.vue',
                'meta' => [
                    'hidden' => $v[SysMenuConst::Hidden],
                    'keepAlive' => true,
                    'type' => $v[SysMenuConst::TypeId],
                    'title' => $v[SysMenuConst::Name],
                    'icon' => $v[SysMenuConst::Icon]
                ],
            ];
            $menus[] = $m;
        }

        $tool=[
            [
                'path'=>"/one", 'parentPath'=>"/", 'name'=>"one", 'rank'=>101,  'component'=>"tool/index.vue",
                'meta'=>['type'=>"menu",'keepAlive' => true, 'title'=>"推广工具", "icon"=> "../../../public/img/onebpSearch38.svg", 'hidden'=>0],
            ],[
                'path'=>"/one/onebpSearch", 'parentPath'=>"/one", 'name'=>"one/onebpSearch", 'rank'=>101,  'component'=>"tool/index.vue",
                'meta'=>['type'=>"menu",'keepAlive' => true, 'title'=>"关键词推广", "icon"=> "../../../public/img/onebpSearch38.svg", 'hidden'=>0],
            ], [
                'path'=>"/one/onebpDisplay", 'parentPath'=>"/one", 'name'=>"one/onebpDisplay", 'rank'=>102, 'component'=>"tool/index.vue",
                'meta'=>['type'=>"menu",'keepAlive' => true, 'title'=>"精准人群推广", "icon"=> "../../../public/img/onebpDisplay38.svg", 'hidden'=>0],
            ],[
                'path'=>"/one/product", 'parentPath'=>"/one", 'name'=>"one/product", 'rank'=>103,  'component'=>"vlist/index.vue",
                'meta'=>['type'=>"menu",'keepAlive' => true, 'title'=>"货品运营", "icon"=> "../../../public/img/onebpAdStrategyItem38.svg", 'hidden'=>0],
            ],
            [
                'path'=>"/one/consumer", 'parentPath'=>"/one", 'name'=>"one/consumer", 'rank'=>104, 'component'=>"vlist/index.vue",
                'meta'=>['type'=>"menu",'keepAlive' => true, 'title'=>"消费者运营", "icon"=> "../../../public/img/onebpAdStrategyCustomer38.svg", 'hidden'=>0],
            ],  [
                'path'=>"/one/onebpMultiAim", 'parentPath'=>"/one", 'name'=>"one/onebpMultiAim", 'rank'=>105, 'component'=>"tool/index.vue",
                'meta'=>['type'=>"menu",'keepAlive' => true, 'title'=>"多目标直投", "icon"=> "../../../public/img/onebpMultiAim38.svg", 'hidden'=>0],
            ],   [
                'path'=>"/one/onebpSite", 'parentPath'=>"/one", 'name'=>"one/onebpSite", 'rank'=>106, 'component'=>"tool/index.vue",
                'meta'=>['type'=>"menu",'keepAlive' => true, 'title'=>"全站推广", "icon"=> "../../../public/img/onebpSite38.svg", 'hidden'=>0],
            ],[
                'path'=>"/one/product/onebpAdStrategyProductSpeed", 'parentPath'=>"/one/product", 'name'=>"one/product/onebpAdStrategyProductSpeed", 'rank'=>2, 'component'=>"tool/index.vue",
                'meta'=>['type'=>"menu",'keepAlive' => true, 'title'=>"货品加速", "icon"=> "../../../public/img/onebpAdStrategyProductSpeed38.svg", 'hidden'=>0],
            ],[
                'path'=>"/one/product/onebpItemMarketing", 'parentPath'=>"/one/product", 'name'=>"one/product/onebpItemMarketing", 'rank'=>1, 'component'=>"tool/index.vue",
                'meta'=>['type'=>"menu",'keepAlive' => true, 'title'=>"货品运营(New)", "icon"=> "../../../public/img/onebpMultiAim38.svg", 'hidden'=>0],
            ],[
                'path'=>"/one/product/onebpAdStrategyCeKuan", 'parentPath'=>"/one/product", 'name'=>"one/product/onebpAdStrategyCeKuan", 'rank'=>3, 'component'=>"tool/index.vue",
                'meta'=>['type'=>"menu",'keepAlive' => true, 'title'=>"测款快", "icon"=> "../../../public/img/onebpAdStrategyCeKuan38.svg", 'hidden'=>0],
            ],[
                'path'=>"/one/product/onebpAdStrategyShangXin", 'parentPath'=>"/one/product", 'name'=>"one/product/onebpAdStrategyShangXin", 'rank'=>4, 'component'=>"tool/index.vue",
                'meta'=>['type'=>"menu",'keepAlive' => true, 'title'=>"上新快", "icon"=> "../../../public/img/onebpAdStrategyShangXin38.svg", 'hidden'=>0],
            ],[
                'path'=>"/one/consumer/onebpAdStrategyLiuZi", 'parentPath'=>"/one/consumer", 'name'=>"one/consumer/onebpAdStrategyLiuZi", 'rank'=>1,'component'=>"tool/index.vue",
                'meta'=>['type'=>"menu",'keepAlive' => true, 'title'=>"易获客", "icon"=> "../../../public/img/onebpAdStrategyLiuZi38.svg", 'hidden'=>0],
            ],[
                'path'=>"/one/consumer/onebpAdStrategyDkx", 'parentPath'=>"/one/consumer", 'name'=>"one/consumer/onebpAdStrategyDkx", 'rank'=>1,'component'=>"tool/index.vue",
                'meta'=>['type'=>"menu",'keepAlive' => true, 'title'=>"拉新快", "icon"=> "../../../public/img/onebpAdStrategyDkx38.svg", 'hidden'=>0],
            ],[
                'path'=>"/one/consumer/onebpAdStrategyRuHui", 'parentPath'=>"/one/consumer", 'name'=>"one/consumer/onebpAdStrategyRuHui", 'rank'=>1,'component'=>"tool/index.vue",
                'meta'=>['type'=>"menu",'keepAlive' => true, 'title'=>"会员快", "icon"=> "../../../public/img/onebpAdStrategyRuHui38.svg", 'hidden'=>0],
            ],[
                'path'=>"/one/consumer/onebpAdStrategyFans", 'parentPath'=>"/one/consumer", 'name'=>"one/consumer/onebpAdStrategyFans", 'rank'=>1,'component'=>"tool/index.vue",
                'meta'=>['type'=>"menu",'keepAlive' => true, 'title'=>"粉丝运营", "icon"=> "../../../public/img/onebpAdStrategyFans38.svg", 'hidden'=>0],
            ],
        ];
        array_push($menus,...$tool);
        $menu = arrlist_sort_by_many_field($menus, 'rank', SORT_ASC);
        $menu2 = arr2tree($menu, 'path', 'parentPath', 'children');
        $this->response('0000', ['data' => $menu2]);
    }

    /**
     * @title   词典列表
     */
    public function action_Dict():void
    {
        $data = $this->SysDict->CacheDict();
        $this->response('0000', ['data' => $data]);
    }

     /**
     * @title   配置信息
     */
    public function action_Config():void
    {
        $config=[
            'OssHost'=>_CONF('OssHost'),
            'ApiOption'=>$this->SysMenu->CacheApiOption(),
            'ApiIndex'=>$this->SysMenu->CacheApiIndex(),
            'put_key'=>_CONF('put_key',''),
        ];
        $this->response('0000', ['data' => $config]);
    }
    // hook api_menu_end.php
}
?>